package com.dana.system.controller.question;


import com.core.controller.BaseController;
import com.core.domain.Result;
import com.core.domain.TableDataInfo;
import com.dana.system.domain.question.dto.QueryQuestionDTO;
import com.dana.system.domain.question.dto.QuestionAddDTO;
import com.dana.system.domain.question.dto.QuestionEditDTO;
import com.dana.system.domain.question.vo.QuestionDetailVO;
import com.dana.system.service.question.IQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/question")
public class QuestionController extends BaseController {
    @Autowired
    private IQuestionService questionService;

    /**
     * 获取题目列表
     */
    @GetMapping("/list")
    public TableDataInfo list(QueryQuestionDTO queryQuestionDTO){
      return getTableDataInfo(questionService.list(queryQuestionDTO));
    }


    /**
     * 添加题目
     * 增删改题目列表的时候需要同给elasticSearch数据
     */
    @PostMapping("/add")
    public Result<Void> add(@RequestBody
                            @Validated QuestionAddDTO questionAddDTO){
        return toResult(questionService.add(questionAddDTO));
    }


    /**
     * 获取题目详情
     */
    @GetMapping("/detail")
    public Result<QuestionDetailVO> detail(Long questionId){
      return  Result.ok(questionService.detail(questionId));
    }

    /**
     * 修改题目内容
     * 增删改题目列表的时候需要同给elasticSearch数据
     */
    @PutMapping("/edit")
    public Result<Void> edit(@RequestBody QuestionEditDTO questionEditDTO){
        return toResult(questionService.edit(questionEditDTO));
    }

    /**
     * 删除题目
     * 增删改题目列表的时候需要同给elasticSearch数据
     */
    @DeleteMapping("/delete")
    public Result<Void> delete(Long questionId){
        return toResult(questionService.delete(questionId));
    }
}
